﻿@model UserAccountViewModel
@{
    var parent = (WebViewPage)TempData["Parent"];
}

@ViewHelpers.Section(parent,
         "change-password",
        @<text>Password Login</text>,
        @<text>
        @if (Config.Current.DeprecateNuGetPasswordLogins)
        {
            <span class="ms-Icon ms-Icon--Warning warning-icon" title="Password login is deprecated, please disable this login." aria-hidden="true"></span>
        }
        <em>@(Model.HasPassword ? "(Enabled)" : "(Disabled)")</em>
        </text>,
        @<text>
        @if (CurrentUser.Confirmed)
        {
            using (Html.BeginForm("ChangePassword", "Users", FormMethod.Post, new { aria_label = "Change password login" }))
            {
                @Html.AntiForgeryToken()
                @Html.ShowValidationMessagesFor(m => m.ChangePassword)

                if (Config.Current.DeprecateNuGetPasswordLogins)
                {
                    <div class="form-group">
                        @if (Model.SignInCredentialCount > 1)
                        {
                            <span>
                                <i class="ms-Icon ms-Icon--Warning warning-icon"></i> Password login is deprecated, please disable this login.
                            </span>
                        }
                        else
                        {
                            <span>
                                <i class="ms-Icon ms-Icon--Warning warning-icon"></i> Password login is deprecated, please link to a Microsoft account and disable this login.
                            </span>
                        }
                    </div>
                }

                if (Model.SignInCredentialCount > 1)
                {
                    <div class="form-group @Html.HasErrorFor(m => m.ChangePassword.DisablePasswordLogin)">
                        <div class="row-checkbox-label">
                            @Html.ShowCheckboxFor(m => m.ChangePassword.DisablePasswordLogin, customClass: "brand-checkbox")
                            @Html.ShowLabelFor(m => m.ChangePassword.DisablePasswordLogin)
                        </div>
                        @Html.ShowValidationMessagesFor(m => m.ChangePassword.DisablePasswordLogin)
                    </div>
                }
                else
                {
                    @Html.HiddenFor(m => m.ChangePassword.DisablePasswordLogin);
                }

                if (Model.HasPassword)
                {
                    <div class="form-group @Html.HasErrorFor(m => m.ChangePassword.OldPassword)">
                        @Html.ShowLabelFor(m => m.ChangePassword.OldPassword)
                        @Html.ShowPasswordFor(m => m.ChangePassword.OldPassword, customClass: "input-brand")
                        @Html.ShowValidationMessagesFor(m => m.ChangePassword.OldPassword)
                    </div>
                    <div class="form-group @Html.HasErrorFor(m => m.ChangePassword.NewPassword)">
                        @Html.ShowLabelFor(m => m.ChangePassword.NewPassword)
                        @Html.ShowPasswordFor(m => m.ChangePassword.NewPassword, customClass: "input-brand")
                        @Html.ShowValidationMessagesFor(m => m.ChangePassword.NewPassword)
                    </div>
                    <div class="form-group @Html.HasErrorFor(m => m.ChangePassword.VerifyPassword)">
                        @Html.ShowLabelFor(m => m.ChangePassword.VerifyPassword)
                        @Html.ShowPasswordFor(m => m.ChangePassword.VerifyPassword, customClass: "input-brand")
                        @Html.ShowValidationMessagesFor(m => m.ChangePassword.VerifyPassword)
                    </div>
                }
                else
                {
                    <p>To enable password login, an email will be sent to '@(CurrentUser.EmailAddress ?? CurrentUser.UnconfirmedEmailAddress)'.</p>
                }

                <div class="row form-group">
                    <div class="col-sm-6">
                        <input type="submit" class="btn btn-brand form-control" value="@(Model.HasPassword ? "Save" : "Enable Password Login")" />
                    </div>
                    <div class="col-sm-6">
                        <button type="button" class="btn btn-brand-secondary form-control" id="cancel-change-password">
                            Cancel
                        </button>
                    </div>
                </div>
            }
        }
        else
        {
            <p>To enable password login, please <a href="@Url.ConfirmationRequired()">confirm</a> your account.</p>
        }
        </text>,
        ViewData.ModelState.Keys.Any(x => x.StartsWith("ChangePassword")))